package shop_servlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class SelectUser {
    public String select_user(String username, String user_id,String phone) {

        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3307/shop?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true",
                    "root","123456");
            stmt = conn.createStatement();
            String sql = "select * from user where user_id='"+ user_id +"' or username='"+ username +"' or phone='"+ phone +"'";

            Integer rtn = stmt.executeUpdate(sql);
            System.out.println(conn);
            return username;
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
            catch (SQLException e) {
                e.printStackTrace();
            }
        }
        // TODO 自动生成的方法存根
        return "null";
    }

}
